package com.tianqu.tms.www.finance.controller;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.www.finance.viewhelper.FinanceDailyReportViewHelper;

public class FinanceDailyReportController  extends TmsController {
	private Logger logger = Logger.getLogger(FinanceDailyReportController.class);

	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();
		try {
			String date = uc.getParameter("date");
			FinanceDailyReportViewHelper view = new FinanceDailyReportViewHelper();
			TransferAcceptedInfo info = TransferAcceptedInfo.getInstance().findDailyAcceptInfo(date.replace("-", ""));
			view.setCountDate(info.getCountDate());
			view.setDailyCount(info.getDailyCount());
			view.setDailyPayment(info.getDailyPayment());
			view.setDailyPaymented(info.getDailyPaymented());
			view.setDailyRemain(info.getDailyRemain());
			view.setDailyTransfer(info.getDailyTransfer());
			view.setDailyWarning(info.getDailyWarning());
			view.setCountDate(info.getCountDate());
			view.setDailyInfo(info.getDailyInfo());
			view.setTotalDailyRemain(info.getTotalDailyRemain());
			controller.commit();
			uc.setAttribute(TmsConstants.VIEWHELP, view);
		} catch (Exception e) {
			logger.error("",e);
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}

		logger.debug(this.getClass().getName() + "#execute was completed.");
	}
}
